package com.uduemc.biso.master.backend.service.impl;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.uduemc.biso.core.extities.center.SysServer;
import com.uduemc.biso.core.feign.SysServerFeign;
import com.uduemc.biso.core.utils.RestResult;
import com.uduemc.biso.core.utils.ResultUtil;
import com.uduemc.biso.master.backend.service.ServermanageService;

@Service
public class ServermanageServiceImpl implements ServermanageService {

	@Autowired
	private SysServerFeign sysServerFeign;

	@Override
	public List<SysServer> getServerByTypeStatus(int type, short status)
			throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
		RestResult restResult = sysServerFeign.findByTypeStatus(type, status);
		@SuppressWarnings("unchecked")
		List<SysServer> data = (List<SysServer>) ResultUtil.data(restResult, new TypeReference<List<SysServer>>() {
		});
		return data;
	}

	@Override
	public SysServer insert(SysServer server)
			throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
		RestResult restResult = sysServerFeign.insert(server);
		SysServer data = ResultUtil.data(restResult, SysServer.class);
		return data;
	}

	@Override
	public SysServer update(SysServer server)
			throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
		RestResult restResult = sysServerFeign.updateById(server);
		SysServer data = ResultUtil.data(restResult, SysServer.class);
		return data;
	}

	@Override
	public SysServer getById(long id)
			throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
		RestResult restResult = sysServerFeign.findOne(id);
		SysServer data = ResultUtil.data(restResult, SysServer.class);
		return data;
	}

	@Override
	public SysServer deleteById(long id)
			throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
		RestResult restResult = sysServerFeign.deleteById(id);
		SysServer data = ResultUtil.data(restResult, SysServer.class);
		return data;
	}

}
